workspace: add the Anchor programs CI never linted, and fix the v1 file that slipped through - #128
Merged
Merged
Conversation
`cargo fmt --check` and `cargo clippy -- -D warnings` both run from the repository root, which only ever sees members of the root workspace. The finance programs each sat in their project's own `anchor/Cargo.toml` workspace and nowhere else, so neither job had ever looked at them. They are now listed in both places: `anchor build` still uses the project workspace, and CI sees the crates. Making that pass took three fixes: - `token-swap` enabled `anchor-spl`'s `metadata` feature without using it. That pulls in `mpl-token-metadata =5.1.2-alpha.2`, which cannot resolve alongside the `^5.1.1` the native token examples ask for, because a caret range excludes pre-releases. The feature is gone rather than dragging five unrelated programs onto an alpha. - The two `mock-switchboard` crates shared a package name, and a lockfile cannot hold two path packages called the same thing. The prop-amm one is now `mock_switchboard_prop_amm`; `[lib] name` stays `mock_switchboard`, so Anchor.toml, the IDL and the .so are untouched, and the dependant renames it back with `package = `. - The lints the crates had never been run through: needless borrows of `.address()` (which returns `&Address` already), unnecessary parentheses, unused `mut`, a manual `is_multiple_of`, and `#[instruction(...)]` parameters that only the `seeds` expression reads. One of those lint fixes was a real bug. Collapsing `transfer_tokens_from_vault`'s eight arguments to six by passing the `BorshAccount` instead of the fields read `event.event_id` after `release_borrow()`, and `BorshAccount`'s `Deref` panics once the borrow is released. All five betting-market tests failed with a panic inside `serialized_account.rs`. `EventSigner` now copies the view, ID and bump out while the borrow is live, which satisfies `too_many_arguments` and makes the ordering something the caller cannot get wrong. Finance tests: betting-market 8, escrow 5, lending 24, order-book 28, perpetual-futures 26, prop-amm 22, token-fundraiser 18, token-swap 21, vault-strategy 22. (cherry picked from commit 29fb3c5) (cherry picked from commit b5a554b)
`cargo fmt --check` and `cargo clippy -- -D warnings` run from the repository root and only see members of the root workspace. 32 Anchor programs were not members, so CI had never looked at them. They used to be. The original workspace in 17afe2e (2023) listed the tokens, compression and oracles programs alongside basics. a70c93b (2024), a commit whose subject is "Adding test jobs github actions for anchor and solana native", deleted every member after `basics/transfer-sol` without mentioning it. The native token entries have been re-added one at a time since, as people touched them; the Anchor ones never were. No commit message, comment or issue justifies the omission, so this restores it. Membership needed three structural fixes: - Five transfer-hook examples all named their crate `transfer-hook`, and one workspace cannot hold two packages with the same name. Each package name now carries its variant. `[lib] name` stays `transfer_hook`, so Anchor.toml, the IDL and the .so are untouched, and nothing path-depends on these crates. - Six Anchor programs genuinely use `anchor-spl`'s `metadata` feature, which requires `mpl-token-metadata =5.1.2-alpha.2`. A caret range excludes pre-releases, so the five native token programs asking for `^5.1.1` could not share a lockfile with them. The native programs now match the pin. That also required bumping their aliased `mpl-solana-program` from 2.3 to 3.0: 5.1.1 accepts `solana-program >=1.14, <3.0` while the alpha requires 3.0, and the mismatch surfaced as "expected `__Pubkey`, found a different `__Pubkey`" where those programs bridge Metaplex's instruction types. - `external-delegate-token-master` enabled the `metadata` feature without using it, so that came off. The lints those crates had never been run through: - Unused imports in the transfer-hook lib.rs files, where the real users import the same names locally. - Needless borrows of `.address()`, which returns `&Address` already. - `.clone()` on `CpiHandle` / `CpiHandleMut`, which are `Copy`. - `mut` on bindings that are already `&mut`. - `#[instruction(...)]` parameters that only a `seeds` expression reads. - Three crates were missing the `unexpected_cfgs` check-cfg declaration the rest of the repository carries. Two findings needed more than the mechanical fix. The `DISCRIMINATOR_MAP`, `EXECUTE_DISCRIMINATOR` and `TX_HOOK_DISCRIMINATOR` constants read as dead code because their only user is the `#[cfg(target_os = "solana")]` entrypoint, which the host build compiles out; they are now gated the same way rather than deleted. `create_collection`'s account fields were private, which made the one field no handler reads look unused; they are `pub` now, like every other accounts struct here. All 56 Anchor projects build and pass: 258 tests. (cherry picked from commit ea2910c) (cherry picked from commit e24c1dd)
`perps: let the pool authority retune the funding rate` landed on main after the v2 port, written against v1: `Context<T>` rather than `&mut Context<T>`, `Signer<'info>`, `Box<Account<'info, Pool>>`, and `has_one = authority`. It does not compile, and nothing caught it, because `perpetual-futures` was not a root workspace member, so neither `cargo clippy` nor `cargo fmt --check` ever saw the crate. Adding the members in this branch is what surfaced it. The port is the usual set: `&mut Context<T>`, the `'info` lifetime dropped, `Box<BorshAccount<Pool>>` to match every sibling handler, and `has_one` replaced by `address = pool.authority` on the signer. Also formats main's new lending and perpetual-futures test code, unformatted for the same reason. perpetual-futures 28 tests, lending 26.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces #126, whose content never reached
main. That PR shows as merged, but its base wasclaude/anchor-v2-migration-d5hkh4rather thanmain, and that branch had already merged, so the merge went into a dead branch. This branch is offmainand carries the same work plus one fix.maindoes not currently compile.perps: let the pool authority retune the funding ratelanded after the v2 port, written against v1:Context<T>rather than&mut Context<T>,Signer<'info>,Box<Account<'info, Pool>>, andhas_one = authority. Nothing caught it, becauseperpetual-futuresis not a root workspace member, socargo clippyandcargo fmt --checknever see the crate. Adding the members here is what surfaced it. The port is the usual set, withBox<BorshAccount<Pool>>to match every sibling handler andaddress = pool.authorityreplacinghas_one.Main's new lending and perpetual-futures test code was also unformatted, for the same reason.
What the workspace change does
cargo fmt --checkandcargo clippy -- -D warningsrun from the repository root and only see members of the root workspace. 32 Anchor programs were not members. This takes the workspace from 61 members to 101.They used to be members. The original workspace in
17afe2e7(2023) listed the tokens, compression and oracles programs alongside basics.a70c93ba(2024), whose subject is "test: Adding test jobs github actions for anchor and solana native", deleted every member afterbasics/transfer-solwithout mentioning it. The native token entries have been re-added one at a time since; the Anchor ones never were.Three structural fixes
transfer-hook, and one workspace cannot hold two packages with the same name. Each package name now carries its variant.[lib] namestaystransfer_hook, soAnchor.toml, the IDL and the.soare untouched.anchor-spl'smetadatafeature, which requiresmpl-token-metadata =5.1.2-alpha.2. A caret range excludes pre-releases, so the five native token programs asking for^5.1.1could not share a lockfile with them. The native programs now match the pin, which also required bumping their aliasedmpl-solana-programfrom 2.3 to 3.0. The native token examples now compile against a prerelease Metaplex.external-delegate-token-masterenabled themetadatafeature without using it, so that came off.The lints those crates had never been run through
Unused imports, needless borrows of
.address(),.clone()onCpiHandle/CpiHandleMut(bothCopy),muton bindings already&mut,#[instruction(...)]parameters only aseedsexpression reads, and three crates missing theunexpected_cfgsdeclaration the rest of the repository carries.Two needed judgement.
DISCRIMINATOR_MAP,EXECUTE_DISCRIMINATORandTX_HOOK_DISCRIMINATORread as dead code because their only user is the#[cfg(target_os = "solana")]entrypoint the host build compiles out; they are gated the same way rather than deleted.create_collection's account fields were private, making the one field no handler reads look unused; they arepubnow.One lint fix was a real bug caught by the tests. Collapsing
transfer_tokens_from_vault's eight arguments by passing theBorshAccountinstead of the fields readevent.event_idafterrelease_borrow(), andBorshAccount'sDerefpanics once released. All five betting-market tests failed insideserialized_account.rs.EventSignernow copies the view, ID and bump out while the borrow is live.Verification
101 workspace members resolve.
cargo fmt --checkandcargo clippy -- -D warnings -A clippy::diverging_sub_expressionclean across all of them. perpetual-futures 28 tests, lending 26, both passing.Generated by Claude Code